﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace lINQtoSQL
{
   public class DAOClass
    {


        public static void InsertCustomer(string CustomerID,
            string CompanyName, string ContractName, string ContractTitle,
            string Address, string City, string Region, string PostalCode,
            string Country, string Phone, string Fax)
        {
            DataClassesNorthwindDataContext context = new DataClassesNorthwindDataContext();
            using (context)
            {
                Customer newCustomer = new Customer()
                {
                    CustomerID = CustomerID,
                    CompanyName = CompanyName,
                    ContactName = ContractName,
                    ContactTitle = ContractTitle,
                    Address = Address,
                    City = City,
                    Region = Region,
                    PostalCode = PostalCode,
                    Country = Country,
                    Phone = Phone,
                    Fax = Fax
                };
                context.Customers.InsertOnSubmit(newCustomer);
                context.SubmitChanges();

            }
        }

        public static void UpdateCustomer(string changeID,
     string CompanyName, string ContractName, string ContractTitle,
     string Address, string City, string Region, string PostalCode,
     string Country, string Phone, string Fax)
        {
            DataClassesNorthwindDataContext context = new DataClassesNorthwindDataContext();
            using (context)
            {
                var customer =
                (from c in context.Customers
                 where c.CustomerID == changeID
                 select c).First();

                    customer.CompanyName = CompanyName;
                    customer.ContactName = ContractName;
                    customer.ContactTitle = ContractTitle;
                    customer. Address = Address;
                    customer.City = City;
                    customer. Region = Region;
                    customer.PostalCode = PostalCode;
                    customer.Country = Country;
                    customer.Phone = Phone;
                    customer.Fax = Fax;

                    context.SubmitChanges();
            }
        }


        public static void DeleteCustomer(string deleteID)
        {
            DataClassesNorthwindDataContext context = new DataClassesNorthwindDataContext();
            using (context)
            {
                var customer =
                (from c in context.Customers
                where c.CustomerID == deleteID
                select c).First();

                context.Customers.DeleteOnSubmit(customer);
                context.SubmitChanges();

            }
        }

    }
}
